// ----------------------------------
// RSDK Project:  Sonic CDSR
// Script Description: LockOut Object 
// Script Author: Twanvanb1
// ----------------------------------

#alias Object.Value0	:	Object.RectAlpha
#alias Object.Value1	:	Object.RotoScaleSpeed



#alias 0	:	LockOut_State_Init
#alias 1	:	LockOut_State_FadeIn
#alias 2	:	LockOut_State_Wait
#alias 3	:	LockOut_State_GoToDevMenu

// Soundtrack
#alias 0	:	OST_JP

// Priority
#alias 1	:	PRIORITY_ACTIVE

// Engine States
#alias 2	:	ENGINE_INITDEVMENU
#alias 6	:	ENGINE_EXIT_HIRESMODE

sub ObjectMain
    switch Object.State
    case LockOut_State_Init
        Object.Alpha = 248
        StopMusic(0)

        ReadSaveRAM()
		// First, restore the Soundtrack setting to what it should be
		Options.Soundtrack = SaveRAM[38]

        Object.State++
        break

    case LockOut_State_FadeIn
        if Object.Alpha == 0
            Object.Alpha = 0
        else 
            Object.Alpha -= 8
        end if

        // display the error message
        object.RotoScaleSpeed -= 2
        sin(object.scale, object.RotoScaleSpeed)
        sin(object.rotation, object.RotoScaleSpeed)
        CheckEqual(object.scale, 512)
        if checkResult == true
            PlayMusic(0)
            Object.State = LockOut_State_Wait 
        end if
        break

    case LockOut_State_Wait
        Object.Alpha = 0

        CheckTouchRect(0, 0, Screen.XSize, Screen.YSize)
		if CheckResult > -1
			Object.State++
		end if

        CheckEqual(KeyPress[0].ButtonA,true)
        TempValue0 = CheckResult
        CheckEqual(KeyPress[0].ButtonB,true)
        TempValue0 |= CheckResult
        CheckEqual(KeyPress[0].ButtonC,true)
        TempValue0 |= CheckResult
        CheckEqual(KeyPress[0].Start,true)
        TempValue0 |= CheckResult

        if TempValue0 == true
			Object.State++
		end if
        break

    case LockOut_State_GoToDevMenu
        object.RotoScaleSpeed -= 2
        music.volume--
        sin(object.scale, object.RotoScaleSpeed)
        sin(object.rotation, object.RotoScaleSpeed)

        CheckEqual(object.scale, 0)
        if checkResult == true
            Engine.State = ENGINE_INITDEVMENU
        end if
        break

    end switch	
end sub

sub ObjectDraw
    DrawRect(0, 0, Screen.XSize, Screen.YSize, 0, 0, 0, 255)
    
    if object.state >= LockOut_State_FadeIn
#platform: Standard
#platform: HW_Rendering
	    DrawSpriteScreenFX(0, FX_ROTOZOOM, Screen.CenterX, Screen.CenterY)
#endplatform

#platform: SW_Rendering
	    DrawSpriteScreenFX(3, FX_ROTOZOOM, Screen.CenterX, Screen.CenterY)
#endplatform
#endplatform

#platform: Mobile
	    DrawSpriteScreenFX(1, FX_ROTOZOOM, Screen.CenterX, Screen.CenterY)
#endplatform

#platform: Use_Origins
	    DrawSpriteScreenFX(2, FX_ROTOZOOM, Screen.CenterX, Screen.CenterY)
#endplatform
end if
    SetScreenFade(0, 0, 0, Object.Alpha)
end sub

sub ObjectStartup
	LoadSpriteSheet("LockOut/Error.gif")

	SetMusicTrack("US/GameOver.ogg", 0, 1)
    
    SpriteFrame(-116, -52, 232, 104, 1, 1) // #0 - Hardware Renderer
    SpriteFrame(-116, -52, 232, 104, 1, 106) // #1 - Mobile
    SpriteFrame(-116, -52, 232, 104, 1, 211) // #2 - Sonic Origins (Plus)
    SpriteFrame(-116, -52, 232, 104, 234, 1)  // #3 - Default

    Object[0].Type = TypeName[Lock Out Screen]
	Object[0].Priority = PRIORITY_ACTIVE
	Object[0].scale = 0
	Object[0].rotation = 0
#platform: HW_Rendering
	Object[0].DrawOrder = 5
#endplatform

    Engine.State = ENGINE_EXIT_HIRESMODE
end sub

// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("LockOut/ErrorMP.gif")
	LoadSpriteSheet("LockOut/ErrorHW.gif")
	LoadSpriteSheet("LockOut/ErrorSO.gif")
	SpriteFrame(-160, -120, 320, 240, 0, 0)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub